vulkan: Add push constants to fragment shader
authorBenjamin Otte <otte@redhat.com>
Tue, 17 Jan 2017 04:20:07 +0000 (05:20 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 17 Jan 2017 05:17:55 +0000 (06:17 +0100)
That way we don't need to move the clip rounded rect manually through
the vertex shader into the fragment shader but can just look at the push
constants.

Simplifies shaders a lot.

23 files changed:
gsk/gskvulkanpushconstants.c
gsk/gskvulkanpushconstantsprivate.h
gsk/gskvulkanrenderpass.c
gsk/resources/vulkan/blend-clip-rounded.frag.glsl
gsk/resources/vulkan/blend-clip-rounded.frag.spv
gsk/resources/vulkan/blend-clip-rounded.vert.glsl
gsk/resources/vulkan/blend-clip-rounded.vert.spv
gsk/resources/vulkan/border-clip-rounded.frag.glsl
gsk/resources/vulkan/border-clip-rounded.frag.spv
gsk/resources/vulkan/border-clip-rounded.vert.glsl
gsk/resources/vulkan/border-clip-rounded.vert.spv
gsk/resources/vulkan/color-clip-rounded.frag.glsl
gsk/resources/vulkan/color-clip-rounded.frag.spv
gsk/resources/vulkan/color-clip-rounded.vert.glsl
gsk/resources/vulkan/color-clip-rounded.vert.spv
gsk/resources/vulkan/color-matrix-clip-rounded.frag.glsl
gsk/resources/vulkan/color-matrix-clip-rounded.frag.spv
gsk/resources/vulkan/color-matrix-clip-rounded.vert.glsl
gsk/resources/vulkan/color-matrix-clip-rounded.vert.spv
gsk/resources/vulkan/linear-clip-rounded.frag.glsl
gsk/resources/vulkan/linear-clip-rounded.frag.spv
gsk/resources/vulkan/linear-clip-rounded.vert.glsl
gsk/resources/vulkan/linear-clip-rounded.vert.spv

index 34574c2532459dfa673778c256d438bed9bec6c7..769f3dbbbb05ca48c92445aa329abc42b0cc2de4 100644 (file)
@@ -4,6 +4,16 @@
 
 #include "gskroundedrectprivate.h"
 
+typedef struct _GskVulkanPushConstantsWire GskVulkanPushConstantsWire;
+
+struct _GskVulkanPushConstantsWire
+{
+  struct {
+    float mvp[16];
+    float clip[12];
+  } common;
+};
+
 void
 gsk_vulkan_push_constants_init (GskVulkanPushConstants  *constants,
                                 const graphene_matrix_t *mvp,
@@ -62,14 +72,14 @@ static void
 gsk_vulkan_push_constants_wire_init (GskVulkanPushConstantsWire   *wire,
                                      const GskVulkanPushConstants *self)
 {
-  graphene_matrix_to_float (&self->mvp, wire->vertex.mvp);
-  gsk_rounded_rect_to_float (&self->clip.rect, wire->vertex.clip);
+  graphene_matrix_to_float (&self->mvp, wire->common.mvp);
+  gsk_rounded_rect_to_float (&self->clip.rect, wire->common.clip);
 }
 
 void
-gsk_vulkan_push_constants_push_vertex (const GskVulkanPushConstants *self,
-                                       VkCommandBuffer               command_buffer,
-                                       VkPipelineLayout              pipeline_layout)
+gsk_vulkan_push_constants_push (const GskVulkanPushConstants *self,
+                                VkCommandBuffer               command_buffer,
+                                VkPipelineLayout              pipeline_layout)
 {
   GskVulkanPushConstantsWire wire;
 
@@ -77,26 +87,11 @@ gsk_vulkan_push_constants_push_vertex (const GskVulkanPushConstants *self,
 
   vkCmdPushConstants (command_buffer,
                       pipeline_layout,
-                      VK_SHADER_STAGE_VERTEX_BIT,
-                      G_STRUCT_OFFSET (GskVulkanPushConstantsWire, vertex),
-                      sizeof (wire.vertex),
-                      &wire.vertex);
-}
-
-#if 0
-void
-gsk_vulkan_push_constants_push_fragment (GskVulkanPushConstants *self,
-                                         VkCommandBuffer         command_buffer,
-                                         VkPipelineLayout        pipeline_layout)
-{
-  vkCmdPushConstants (command_buffer,
-                      pipeline_layout,
-                      VK_SHADER_STAGE_FRAGMENT_BIT,
-                      G_STRUCT_OFFSET (GskVulkanPushConstants, fragment),
-                      sizeof (self->fragment),
-                      &self->fragment);
+                      VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
+                      G_STRUCT_OFFSET (GskVulkanPushConstantsWire, common),
+                      sizeof (wire.common),
+                      &wire.common);
 }
-#endif
 
 uint32_t
 gst_vulkan_push_constants_get_range_count (void)
@@ -109,16 +104,9 @@ gst_vulkan_push_constants_get_ranges (void)
 {
   static const VkPushConstantRange ranges[1] = {
       {
-          .stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
-          .offset = G_STRUCT_OFFSET (GskVulkanPushConstantsWire, vertex),
-          .size = sizeof (((GskVulkanPushConstantsWire *) 0)->vertex)
-#if 0
-      },
-      {
-          .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
-          .offset = G_STRUCT_OFFSET (GskVulkanPushConstants, fragment),
-          .size = sizeof (((GskVulkanPushConstants *) 0)->fragment)
-#endif
+          .stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
+          .offset = G_STRUCT_OFFSET (GskVulkanPushConstantsWire, common),
+          .size = sizeof (((GskVulkanPushConstantsWire *) 0)->common)
       }
   };
 
index 4642d526a3a8fca624b08d543d1e5f9a074a10d4..f1652c98affaea1abdc2713711c9fde84772ad7a 100644 (file)
@@ -8,7 +8,6 @@
 G_BEGIN_DECLS
 
 typedef struct _GskVulkanPushConstants GskVulkanPushConstants;
-typedef struct _GskVulkanPushConstantsWire GskVulkanPushConstantsWire;
 
 struct _GskVulkanPushConstants
 {
@@ -16,18 +15,6 @@ struct _GskVulkanPushConstants
   GskVulkanClip clip;
 };
 
-struct _GskVulkanPushConstantsWire
-{
-  struct {
-    float mvp[16];
-    float clip[12];
-  } vertex;
-#if 0
-  struct {
-  } fragment;
-#endif
-};
-
 const VkPushConstantRange *
                         gst_vulkan_push_constants_get_ranges            (void) G_GNUC_PURE;
 uint32_t                gst_vulkan_push_constants_get_range_count       (void) G_GNUC_PURE;
@@ -49,7 +36,7 @@ gboolean                gsk_vulkan_push_constants_intersect_rounded     (GskVulk
                                                                          const GskVulkanPushConstants   *src,
                                                                          const GskRoundedRect           *rect);
 
-void                    gsk_vulkan_push_constants_push_vertex           (const GskVulkanPushConstants   *self,
+void                    gsk_vulkan_push_constants_push                  (const GskVulkanPushConstants   *self,
                                                                          VkCommandBuffer                 command_buffer,
                                                                          VkPipelineLayout                pipeline_layout);
 
index c92375e30ba1d5daf917100179c46393bf8fed33..619a1172b30c33d3ce9026651f8109838db73a57 100644 (file)
@@ -886,9 +886,9 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass     *self,
           break;
 
         case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
-          gsk_vulkan_push_constants_push_vertex (&op->constants.constants,
-                                                 command_buffer, 
-                                                 gsk_vulkan_pipeline_layout_get_pipeline_layout (layout));
+          gsk_vulkan_push_constants_push (&op->constants.constants,
+                                          command_buffer, 
+                                          gsk_vulkan_pipeline_layout_get_pipeline_layout (layout));
           break;
 
         default:
index fb1c14808cabd4850374ab72c7ecc20a0ad3a295..23ef1c83d790c33569ecfdc5eb8cb4c3d0e4add1 100644 (file)
@@ -1,5 +1,7 @@
 #version 420 core
 
+#include "constants.glsl"
+
 struct RoundedRect {
   vec4 bounds;
   vec4 corners;
@@ -7,8 +9,6 @@ struct RoundedRect {
 
 layout(location = 0) in vec2 inPos;
 layout(location = 1) in vec2 inTexCoord;
-layout(location = 2) in flat vec4 inClipBounds;
-layout(location = 3) in flat vec4 inClipWidths;
 
 layout(set = 0, binding = 0) uniform sampler2D inTexture;
 
@@ -51,7 +51,7 @@ float clip(vec2 pos, RoundedRect r) {
 
 void main()
 {
-  RoundedRect r = RoundedRect(vec4(inClipBounds.xy, inClipBounds.xy + inClipBounds.zw), inClipWidths);
+  RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw), push.clip_widths);
 
   color = texture (inTexture, inTexCoord) * clip (inPos, r);
 }
index aa407c2d1bdd84e1c9bce556022ab5322e483643..adaa02be7221189fcce93b3845280f4d51f7ed1d 100644 (file)
Binary files a/gsk/resources/vulkan/blend-clip-rounded.frag.spv and b/gsk/resources/vulkan/blend-clip-rounded.frag.spv differ
index 221cbbeebab361211d165b6a6cfb28020e97a782..0a5f31d79c0e3421cdfabac345421d0889be934a 100644 (file)
@@ -7,8 +7,6 @@ layout(location = 1) in vec4 inTexRect;
 
 layout(location = 0) out vec2 outPos;
 layout(location = 1) out vec2 outTexCoord;
-layout(location = 2) out flat vec4 outClipBounds;
-layout(location = 3) out flat vec4 outClipWidths;
 
 out gl_PerVertex {
   vec4 gl_Position;
@@ -37,8 +35,6 @@ void main() {
   gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
 
   outPos = pos;
-  outClipBounds = push.clip_bounds;
-  outClipWidths = push.clip_widths;
 
   vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
                       rect.zw / inRect.zw);
index 2a2d7ce9a408a3ef072cec494aafb9faed33150d..bc82237ef54a94f68d8cd50bd23535ae82208470 100644 (file)
Binary files a/gsk/resources/vulkan/blend-clip-rounded.vert.spv and b/gsk/resources/vulkan/blend-clip-rounded.vert.spv differ
index bf4ad650b114dcbde1edad1def5f43852d3791e6..d31718abb9e39d02da7d1ca8f83c2caa9bf5bb7e 100644 (file)
@@ -1,5 +1,6 @@
 #version 420 core
 
+#include "constants.glsl"
 #include "rounded-rect.glsl"
 
 layout(location = 0) in vec2 inPos;
@@ -8,16 +9,13 @@ layout(location = 2) in vec4 inRect;
 layout(location = 3) in vec4 inCornerWidths;
 layout(location = 4) in vec4 inCornerHeights;
 layout(location = 5) in vec4 inBorderWidths;
-layout(location = 6) in flat vec4 inClipBounds;
-layout(location = 7) in flat vec4 inClipWidths;
-layout(location = 8) in flat vec4 inClipHeights;
 
 layout(location = 0) out vec4 color;
 
 vec4
 clip (vec4 color)
 {
-  RoundedRect r = RoundedRect (vec4(inClipBounds.xy, inClipBounds.xy + inClipBounds.zw), inClipWidths, inClipHeights);
+  RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw), push.clip_widths, push.clip_heights);
 
   return color * rounded_rect_coverage (r, inPos);
 }
index 401d7ae1c644151f3542873c08f79f737ad2a4ee..3be544337c20d88fe019901d4f3975ba41abbcf5 100644 (file)
Binary files a/gsk/resources/vulkan/border-clip-rounded.frag.spv and b/gsk/resources/vulkan/border-clip-rounded.frag.spv differ
index a66d7f78dc9437745398d73699d446a0e2739dc3..8db91a58a4b48ace963eba702f98cf77d604f9d8 100644 (file)
@@ -14,9 +14,6 @@ layout(location = 2) out flat vec4 outRect;
 layout(location = 3) out flat vec4 outCornerWidths;
 layout(location = 4) out flat vec4 outCornerHeights;
 layout(location = 5) out flat vec4 outBorderWidths;
-layout(location = 6) out flat vec4 outClipBounds;
-layout(location = 7) out flat vec4 outClipWidths;
-layout(location = 8) out flat vec4 outClipHeights;
 
 out gl_PerVertex {
   vec4 gl_Position;
@@ -112,7 +109,4 @@ void main() {
   outCornerWidths = inCornerWidths;
   outCornerHeights = inCornerHeights;
   outBorderWidths = inBorderWidths;
-  outClipBounds = push.clip_bounds;
-  outClipWidths = push.clip_widths;
-  outClipHeights = push.clip_heights;
 }
index 527168616730a55869060d53506ee6fa6095d492..ce5e85e3dce516d82e033bb5e2dd1f906e25c462 100644 (file)
Binary files a/gsk/resources/vulkan/border-clip-rounded.vert.spv and b/gsk/resources/vulkan/border-clip-rounded.vert.spv differ
index 515a9989e78b91a238a10e44dffa362639557c4e..c1fa5038d5c96a181e73afec2a85d62891eb4fa5 100644 (file)
@@ -1,9 +1,9 @@
 #version 420 core
 
+#include "constants.glsl"
+
 layout(location = 0) in vec2 inPos;
 layout(location = 1) in vec4 inColor;
-layout(location = 2) in vec4 inClipBounds;
-layout(location = 3) in vec4 inClipWidths;
 
 layout(location = 0) out vec4 color;
 
@@ -50,7 +50,7 @@ float clip(vec2 pos, RoundedRect r) {
 
 void main()
 {
-    RoundedRect r = RoundedRect(vec4(inClipBounds.xy, inClipBounds.xy + inClipBounds.zw), inClipWidths);
+  RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw), push.clip_widths);
 
-    color = vec4(inColor.rgb * inColor.a, inColor.a) * clip (inPos, r);
+  color = vec4(inColor.rgb * inColor.a, inColor.a) * clip (inPos, r);
 }
index cf650af95c1e4dfd8adf4a9f3e785c175552c639..ce925764d411b2647b4da32cfbd0bc97748b9e85 100644 (file)
Binary files a/gsk/resources/vulkan/color-clip-rounded.frag.spv and b/gsk/resources/vulkan/color-clip-rounded.frag.spv differ
index 2303d90e70e53a9a185c023988853d5ee687e080..985a174f97e5670519dad4dde1401a08c7699097 100644 (file)
@@ -7,8 +7,6 @@ layout(location = 1) in vec4 inColor;
 
 layout(location = 0) out vec2 outPos;
 layout(location = 1) out flat vec4 outColor;
-layout(location = 2) out flat vec4 outClipBounds;
-layout(location = 3) out flat vec4 outClipWidths;
 
 out gl_PerVertex {
   vec4 gl_Position;
@@ -26,6 +24,4 @@ void main() {
   gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
   outPos = pos;
   outColor = inColor;
-  outClipBounds = push.clip_bounds;
-  outClipWidths = push.clip_widths;
 }
index b28355446742af9ee4540fa8e646452aea568189..941189cf448a40eb49e27cd54a70dea7ac9687e6 100644 (file)
Binary files a/gsk/resources/vulkan/color-clip-rounded.vert.spv and b/gsk/resources/vulkan/color-clip-rounded.vert.spv differ
index c0e42cac6d8680b70ca9181b35facea74ae62ce0..6015aee752f44995a3716606f83b73bdbbf65043 100644 (file)
@@ -1,5 +1,7 @@
 #version 420 core
 
+#include "constants.glsl"
+
 struct RoundedRect {
   vec4 bounds;
   vec4 corners;
@@ -7,10 +9,8 @@ struct RoundedRect {
 
 layout(location = 0) in vec2 inPos;
 layout(location = 1) in vec2 inTexCoord;
-layout(location = 2) in flat vec4 inClipBounds;
-layout(location = 3) in flat vec4 inClipWidths;
-layout(location = 4) in flat mat4 inColorMatrix;
-layout(location = 8) in flat vec4 inColorOffset;
+layout(location = 2) in flat mat4 inColorMatrix;
+layout(location = 6) in flat vec4 inColorOffset;
 
 layout(set = 0, binding = 0) uniform sampler2D inTexture;
 
@@ -70,7 +70,7 @@ color_matrix (vec4 color, mat4 color_matrix, vec4 color_offset)
 
 void main()
 {
-  RoundedRect r = RoundedRect(vec4(inClipBounds.xy, inClipBounds.xy + inClipBounds.zw), inClipWidths);
+  RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw), push.clip_widths);
 
   color = color_matrix (texture (inTexture, inTexCoord), inColorMatrix, inColorOffset) * clip (inPos, r);
 }
index f4c753aae688db2c02d395969f61ed8772d4b72d..f0a36e010c8729acc849f396b495e28ecfb283e4 100644 (file)
Binary files a/gsk/resources/vulkan/color-matrix-clip-rounded.frag.spv and b/gsk/resources/vulkan/color-matrix-clip-rounded.frag.spv differ
index 5d3e3400e630c5c9687ca7e51103b0ec86a32656..1c7f0a43428e110a9914a9b377059f65144e1dec 100644 (file)
@@ -9,10 +9,8 @@ layout(location = 6) in vec4 inColorOffset;
 
 layout(location = 0) out vec2 outPos;
 layout(location = 1) out vec2 outTexCoord;
-layout(location = 2) out flat vec4 outClipBounds;
-layout(location = 3) out flat vec4 outClipWidths;
-layout(location = 4) out flat mat4 outColorMatrix;
-layout(location = 8) out flat vec4 outColorOffset;
+layout(location = 2) out flat mat4 outColorMatrix;
+layout(location = 6) out flat vec4 outColorOffset;
 
 out gl_PerVertex {
   vec4 gl_Position;
@@ -41,8 +39,6 @@ void main() {
   gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
 
   outPos = pos;
-  outClipBounds = push.clip_bounds;
-  outClipWidths = push.clip_widths;
 
   vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
                       rect.zw / inRect.zw);
index d4db4839d1827fba2b328280bbf9fe0c7eae7a17..14b85f53ee5eeaa6100df3c236547139ff728f4d 100644 (file)
Binary files a/gsk/resources/vulkan/color-matrix-clip-rounded.vert.spv and b/gsk/resources/vulkan/color-matrix-clip-rounded.vert.spv differ
index 3c5fade7e3932e2fab7b025e6a91c467af155eb0..4535a44abbe603d7cb637830617bfeade52a75fc 100644 (file)
@@ -1,5 +1,7 @@
 #version 420 core
 
+#include "constants.glsl"
+
 struct ColorStop {
   float offset;
   vec4 color;
@@ -14,9 +16,7 @@ layout(location = 0) in vec2 inPos;
 layout(location = 1) in float inGradientPos;
 layout(location = 2) in flat int inRepeating;
 layout(location = 3) in flat int inStopCount;
-layout(location = 4) in flat vec4 inClipBounds;
-layout(location = 5) in flat vec4 inClipWidths;
-layout(location = 6) in flat ColorStop inStops[8];
+layout(location = 4) in flat ColorStop inStops[8];
 
 layout(location = 0) out vec4 outColor;
 
@@ -57,7 +57,7 @@ float clip(vec2 pos, RoundedRect r) {
 
 void main()
 {
-  RoundedRect r = RoundedRect(vec4(inClipBounds.xy, inClipBounds.xy + inClipBounds.zw), inClipWidths);
+  RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw), push.clip_widths);
 
   float pos;
   if (inRepeating != 0)
index ce8a52a43d6692ebe98fa760ca97e79be8d54d2c..4a018c04149ffaf4b07f31d89481294b26345bef 100644 (file)
Binary files a/gsk/resources/vulkan/linear-clip-rounded.frag.spv and b/gsk/resources/vulkan/linear-clip-rounded.frag.spv differ
index c06021d3cf0dd26fc52d90beedacbe427456d708..fd50e26f5589ab5449e8980e966ef39a22baf3ad 100644 (file)
@@ -27,9 +27,7 @@ layout(location = 0) out vec2 outPos;
 layout(location = 1) out float outGradientPos;
 layout(location = 2) out flat int outRepeating;
 layout(location = 3) out flat int outStopCount;
-layout(location = 4) out flat vec4 outClipBounds;
-layout(location = 5) out flat vec4 outClipWidths;
-layout(location = 6) out flat ColorStop outStops[8];
+layout(location = 4) out flat ColorStop outStops[8];
 
 out gl_PerVertex {
   vec4 gl_Position;
@@ -56,8 +54,6 @@ void main() {
   gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
   outPos = pos;
   outGradientPos = get_gradient_pos (pos);
-  outClipBounds = push.clip_bounds;
-  outClipWidths = push.clip_widths;
   outRepeating = inRepeating;
   outStopCount = inStopCount;
   outStops[0].offset = inOffsets0[0];
index 800e090e916968054bbd1e699d999810082e9892..421516f7eff953b4344215f791bdd3b0c776ca32 100644 (file)
Binary files a/gsk/resources/vulkan/linear-clip-rounded.vert.spv and b/gsk/resources/vulkan/linear-clip-rounded.vert.spv differ